package com.demo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.Nullable;

import com.module.commonui.R;
import com.ns.yc.yccardviewlib.shadow.ShadowLayout;


/**
 * Describe:
 * Created by Rance Rang on 2019-12-21.
 * <p>
 * Copyright (c) Tange.Inc All rights reserved.
 */
public class SpeakingView extends RelativeLayout {

    protected View mView;
    private int mOrientation = 0;
    public RelativeLayout relMicPhone;
    public RecordAudioView btnSpeaking;

    public BreathingLightView lightView;
    public ImageView recordViewIcon;
    public ImageView voiceViewIcon;
    public ShadowLayout recordViewShadowLayout;
    public SpeakingView(Context context) {
        super(context);
    }

    public SpeakingView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs, 0);
        initView(context);
    }

    public SpeakingView(Context context, int orientation) {
        super(context);
        this.mOrientation = orientation;
        initView(context);
    }

    public SpeakingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

        super(context, attrs, defStyleAttr);
        initParam(context, attrs);
        initView(context);
    }

    private void initParam(Context context, @Nullable AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SpeakingView);
        mOrientation = typedArray.getInt(R.styleable.SpeakingView_speaking_orientation, 0);
        typedArray.recycle();
    }


    private void initView(Context context){
        View view = LayoutInflater.from(context).inflate(mOrientation == 0? R.layout.layout_speaking_hor : R.layout.layout_speaking_ver, this, true);
        mView = view;

        relMicPhone = view.findViewById(R.id.rel_camera_live_micphone);
        btnSpeaking = view.findViewById(R.id.btn_camera_live_speaking);
        lightView = view.findViewById(R.id.camera_live_light_view);
        lightView.setStyle(Paint.Style.FILL);
        lightView.setColor(getContext().getResources().getColor(R.color.breathing_light_color));
        lightView.setParentView(btnSpeaking);
        recordViewIcon = view.findViewById(R.id.record_view_icon_inside);
        voiceViewIcon = view.findViewById(R.id.voice_view_icon_inside);
        recordViewShadowLayout = view.findViewById(R.id.yc_shadow_layout);
    }

}
